<template>
    <div class="search-container">
        <div class="tabs-container">
            <el-button
                @click="handleChangeTab(0)"
                :class="activeRef == 0 ? 'active' : ''"
                :type="activeRef == 0 ? '' : 'text'"
            >
                <template #icon>
                    <img src="@/assets/image/visa.png" />
                </template>
                签证
            </el-button>
            <el-button
                @click="handleChangeTab(1)"
                :class="activeRef == 0 ? '' : 'active'"
                :type="activeRef == 0 ? 'text' : ''"
            >
                <template #icon>
                    <img src="@/assets/image/plane.png" />
                </template>
                国际机票
            </el-button>
        </div>
        <div class="search-container">
            <!-- <el-select
                v-model="searchValueRef"
                multiple
                filterable
                allow-create
                default-first-option
                placeholder="请选择文章标签"
            >
                <template #prefix>
                    <el-icon class="el-input__icon">
                        <search @click="handleSearch" />
                    </el-icon>
                </template>
                <el-option
                    v-for="item in hotList"
                    :key="item.name"
                    :label="item.name"
                    :value="item.name"
                ></el-option>
            </el-select>-->
            <el-input
                v-model="searchValueRef"
                @keyup.enter="handleSearch"
                class
                placeholder="搜索办签国家/地区"
            >
                <template #prefix>
                    <el-icon class="el-input__icon">
                        <search @click="handleSearch" />
                    </el-icon>
                </template>
            </el-input>
            <div class="hot-content">
                <span class="title">热门推荐</span>
                <el-check-tag
                    effect="plain"
                    type="info"
                    :checked="checkedRef"
                    v-for="(item) of hotList"
                    :key="item.id"
                    style="margin-right: 8px"
                    @click="handlePushSearchList(item)"
                >{{ item.name }}</el-check-tag>
            </div>
        </div>
    </div>
</template>
<script>
import { reactive, ref } from "vue"
import { Search } from '@element-plus/icons-vue'
export default {
    name: 'homeSearch',
    components: {
        Search
    },
    setup(props, { emit }) {
        let activeRef = ref(0)
        let searchValueRef = ref([])
        let checkedRef = ref(false)
        const hotList = reactive([
            {
                name: '马来西亚',
                id: 1
            },
            {
                name: '越南',
                id: 2
            },
            {
                name: '日本',
                id: 3
            },
            {
                name: '菲律宾',
                id: 4
            },
            {
                name: '泰国',
                id: 5
            },
            {
                name: '新加坡',
                id: 6
            },
        ])
        const changeArea = ((item) => {
            console.log(item)
        })
        const handlePushSearchList = ((item) => {
            if (!searchValueRef.value.includes(item.name)) {
                searchValueRef.value.push(item.name)
            }
        })
        const handleChangeTab = ((value) => {
            activeRef.value = value
        })
        const handleSearch = (() => {
            const value = searchValueRef.value.join(',')
            emit('change-search', value)
        })
        return { activeRef, changeArea, searchValueRef, handleChangeTab, handleSearch, handlePushSearchList, checkedRef, hotList }
    }
}
</script>
<style lang="less">
.search-container {
    box-sizing: border-box;
    .tabs-container {
        width: 351px;
        height: 96px;
        background: #ffffff;
        border-radius: 24px 24px 0px 0px;
        opacity: 1;
        z-index: 200;
        padding: 24px;
        display: flex;
        .el-button {
            width: 114px;
            height: 48px;
            flex: 1;
            font-size: 18px;
            color: #14183e;
        }
        .active {
            background-color: rgba(51, 133, 255, 0.3);
            box-shadow: 0px 20px 70px 1px rgba(241, 165, 1, 0.15);
            border-radius: 10px 10px 10px 10px;
        }
    }
    .search-container {
        width: 1282px;
        height: 161px;
        background: #ffffff;
        box-shadow: 0px 16px 26px 1px rgba(0, 0, 0, 0.09);
        border-radius: 0px 24px 24px 24px;
        opacity: 1;
        padding: 37px 24px 18px 24px;
        .el-input {
            width: 1234px;
            height: 48px;
            .el-input__inner {
                width: 100%;
                height: 100%;
                background: rgba(25, 29, 35, 0.05);
            }
        }
        .hot-content {
            height: 58px;
            display: flex;
            align-items: center;
            .title {
                margin-right: 16px;
                font-size: 14px;
                color: #14183e;
            }
            .el-check-tag {
                background-color: #ffffff;
                border: 1px solid #14183e;
                font-size: 14px;
                font-weight: 400;
            }
        }
    }
}
</style>